<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>TextureSupport</title>
    <link
      rel="shortcut icon"
      type="image/x-icon"
      href="/examples/public/favicon.ico"
    />
    <link rel="stylesheet" href="../css/common.css" />
  </head>

  <style>
    #app {
      width: 100%;
      height: 100%;
      position: relative;
      background-color: black;
    }
  </style>

  <body>
    <div id="app"></div>

    <script type="module">
      import * as THREE from "three";
      import * as Vis from "../../dist/Vis.es.js";
      import { v4 as getUUid } from "uuid";

      const canvasGenerator = new Vis.CanvasGenerator({
        width: 800,
        height: 160,
      })
        .draw((ctx) => {
          ctx.textBaseline = "middle";
          ctx.textAlign = "center";

          ctx.fillStyle = "rgb(206, 42, 230)";

          ctx.font = " bold 72px 微软雅黑";
          ctx.fillText("Texture", 400, 80);
        })
        .preview({
          top: "10%",
          left: "10%",
        });

      const engine = new Vis.ModelingEngineSupport()
        .setDom(document.getElementById("app"))
        .setSize()
        .setStats(true)
        .registerResources({
          "example.canvas": canvasGenerator.get(),
        });

      engine
        .loadResourcesAsync([
          "/examples/public/video/1.mp4",
          "/examples/public/texture/skyBox/snowVillage/nx.jpg",
          "/examples/public/texture/skyBox/snowVillage/ny.jpg",
          "/examples/public/texture/skyBox/snowVillage/nz.jpg",
          "/examples/public/texture/skyBox/snowVillage/px.jpg",
          "/examples/public/texture/skyBox/snowVillage/py.jpg",
          "/examples/public/texture/skyBox/snowVillage/pz.jpg",
        ])
        .then(() => {
          const ambientLight = Vis.generateConfig("AmbientLight");

          const canvasTexture = Vis.generateConfig("CanvasTexture", {
            url: "example.canvas",
          });
          const videoTexture = Vis.generateConfig("VideoTexture", {
            url: "/examples/public/video/1.mp4",
          });
          const cubeTexture = Vis.generateConfig("CubeTexture", {
            cube: {
              nx: "/examples/public/texture/skyBox/snowVillage/nx.jpg",
              ny: "/examples/public/texture/skyBox/snowVillage/ny.jpg",
              nz: "/examples/public/texture/skyBox/snowVillage/nz.jpg",
              px: "/examples/public/texture/skyBox/snowVillage/px.jpg",
              py: "/examples/public/texture/skyBox/snowVillage/py.jpg",
              pz: "/examples/public/texture/skyBox/snowVillage/pz.jpg",
            },
          });

          const spriteMaterial = Vis.generateConfig("SpriteMaterial", {
            map: canvasTexture.vid,
          });

          const box1Material = Vis.generateConfig("MeshStandardMaterial", {
            map: videoTexture.vid,
          });

          const box2Material = Vis.generateConfig("MeshStandardMaterial", {
            roughness: 0,
            metalness: 1,
          });

          const sprite = Vis.generateConfig("Sprite", {
            material: spriteMaterial.vid,
            position: {
              y: 15,
            },
            scale: {
              x: 25,
              y: 5,
            },
          });

          const boxGeometry = Vis.generateConfig("BoxGeometry", {
            width: 20,
            height: 20,
            depth: 20,
          });

          const box1 = Vis.generateConfig("Mesh", {
            geometry: boxGeometry.vid,
            material: box1Material.vid,
            position: {
              x: -15,
            },
          });

          const box2 = Vis.generateConfig("Mesh", {
            geometry: boxGeometry.vid,
            material: box2Material.vid,
            position: {
              x: 15,
            },
          });

          const scene = Vis.generateConfig("Scene", {
            background: cubeTexture.vid,
            environment: cubeTexture.vid,
            children: [ambientLight.vid, box1.vid, box2.vid],
          });

          engine.applyConfig(
            ambientLight,
            canvasTexture,
            videoTexture,
            cubeTexture,
            boxGeometry,
            spriteMaterial,
            box1Material,
            box2Material,
            box1,
            box2,
            scene
          );

          engine.setScene(scene.vid).play();
        });
    </script>
  </body>
</html>
